package com.atom.a3dcamerachange;

import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private Camera3DView mCamera3DView_v, mCamera3DView_h;
    private Camera3DView mCamera3DView_v_3d, mCamera3DView_h_3d;
    private Camera3DView mCamera3DView_v_x, mCamera3DView_h_x;
    private Camera3DView mCamera3DView_v_t, mCamera3DView_h_t;
    private Camera3DView mCamera3DView_v_s, mCamera3DView_h_s;
    private Camera3DView mCamera3DView_v_c, mCamera3DView_h_c;
    private Camera3DView mCamera3DView_v_o, mCamera3DView_h_o;

    private SeekBar mSeekBar;
    private Button mPre, mNext;

    private BitmapDrawable bgDrawable1, bgDrawable2, bgDrawable3, bgDrawable4, bgDrawable5;
    private List<Bitmap> mBitmapList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mSeekBar = (SeekBar) findViewById(R.id.sb_bar);
        mPre = (Button) findViewById(R.id.btn_pre);
        mNext = (Button) findViewById(R.id.btn_next);

        mCamera3DView_v = (Camera3DView) findViewById(R.id.c3d_view_vertical);
        mCamera3DView_h = (Camera3DView) findViewById(R.id.c3d_view_horizontal);

        mCamera3DView_v_3d = (Camera3DView) findViewById(R.id.c3d_view_vertical_3d);
        mCamera3DView_h_3d = (Camera3DView) findViewById(R.id.c3d_view_horizontal_3d);

        mCamera3DView_v_x = (Camera3DView) findViewById(R.id.c3d_view_vertical_x);
        mCamera3DView_h_x = (Camera3DView) findViewById(R.id.c3d_view_horizontal_x);

        mCamera3DView_v_t = (Camera3DView) findViewById(R.id.c3d_view_vertical_t);
        mCamera3DView_h_t = (Camera3DView) findViewById(R.id.c3d_view_horizontal_t);

        mCamera3DView_v_s = (Camera3DView) findViewById(R.id.c3d_view_vertical_s);
        mCamera3DView_h_s = (Camera3DView) findViewById(R.id.c3d_view_horizontal_s);

        mCamera3DView_v_c = (Camera3DView) findViewById(R.id.c3d_view_vertical_c);
        mCamera3DView_h_c = (Camera3DView) findViewById(R.id.c3d_view_horizontal_c);

        mCamera3DView_v_o = (Camera3DView) findViewById(R.id.c3d_view_vertical_o);
        mCamera3DView_h_o = (Camera3DView) findViewById(R.id.c3d_view_horizontal_o);

        mBitmapList = new ArrayList<>();
        bgDrawable1 = (BitmapDrawable) getResources().getDrawable(R.drawable.img1);
        bgDrawable2 = (BitmapDrawable) getResources().getDrawable(R.drawable.img2);
        bgDrawable3 = (BitmapDrawable) getResources().getDrawable(R.drawable.img3);
        bgDrawable4 = (BitmapDrawable) getResources().getDrawable(R.drawable.img4);
        bgDrawable5 = (BitmapDrawable) getResources().getDrawable(R.drawable.img5);
        Bitmap bitmap1 = bgDrawable1.getBitmap();
        Bitmap bitmap2 = bgDrawable2.getBitmap();
        Bitmap bitmap3 = bgDrawable3.getBitmap();
        Bitmap bitmap4 = bgDrawable4.getBitmap();
        Bitmap bitmap5 = bgDrawable5.getBitmap();
        mBitmapList.add(bitmap1);
        mBitmapList.add(bitmap2);
        mBitmapList.add(bitmap3);
        mBitmapList.add(bitmap4);
        mBitmapList.add(bitmap5);


        mCamera3DView_v.addImageBitmaps(mBitmapList);
        mCamera3DView_h.addImageBitmaps(mBitmapList);
        mCamera3DView_v_3d.addImageBitmaps(mBitmapList);
        mCamera3DView_h_3d.addImageBitmaps(mBitmapList);
        mCamera3DView_v_x.addImageBitmaps(mBitmapList);
        mCamera3DView_h_x.addImageBitmaps(mBitmapList);
        mCamera3DView_v_t.addImageBitmaps(mBitmapList);
        mCamera3DView_h_t.addImageBitmaps(mBitmapList);
        mCamera3DView_v_s.addImageBitmaps(mBitmapList);
        mCamera3DView_h_s.addImageBitmaps(mBitmapList);
        mCamera3DView_v_c.addImageBitmaps(mBitmapList);
        mCamera3DView_h_c.addImageBitmaps(mBitmapList);
        mCamera3DView_v_o.addImageBitmaps(mBitmapList);
        mCamera3DView_h_o.addImageBitmaps(mBitmapList);


        mCamera3DView_v.setRollorientation(Camera3DView.VERTICAL);
        mCamera3DView_h.setRollorientation(Camera3DView.HORIZONTAL);
        mCamera3DView_v_3d.setRollorientation(Camera3DView.VERTICAL);
        mCamera3DView_h_3d.setRollorientation(Camera3DView.HORIZONTAL);
        mCamera3DView_v_x.setRollorientation(Camera3DView.VERTICAL);
        mCamera3DView_h_x.setRollorientation(Camera3DView.HORIZONTAL);
        mCamera3DView_v_t.setRollorientation(Camera3DView.VERTICAL);
        mCamera3DView_h_t.setRollorientation(Camera3DView.HORIZONTAL);
        mCamera3DView_v_s.setRollorientation(Camera3DView.VERTICAL);
        mCamera3DView_h_s.setRollorientation(Camera3DView.HORIZONTAL);
        mCamera3DView_v_c.setRollorientation(Camera3DView.VERTICAL);
        mCamera3DView_h_c.setRollorientation(Camera3DView.HORIZONTAL);
        mCamera3DView_v_o.setRollorientation(Camera3DView.VERTICAL);
        mCamera3DView_h_o.setRollorientation(Camera3DView.HORIZONTAL);


        mCamera3DView_v.setRollMode(Camera3DView.RollMode.Roll2D);
        mCamera3DView_h.setRollMode(Camera3DView.RollMode.Roll2D);
        mCamera3DView_v_3d.setRollMode(Camera3DView.RollMode.Whole3D);
        mCamera3DView_h_3d.setRollMode(Camera3DView.RollMode.Whole3D);
        mCamera3DView_v_x.setRollMode(Camera3DView.RollMode.SepartConbine);
        mCamera3DView_h_x.setRollMode(Camera3DView.RollMode.SepartConbine);
        mCamera3DView_v_t.setRollMode(Camera3DView.RollMode.Jalousie);
        mCamera3DView_h_t.setRollMode(Camera3DView.RollMode.Jalousie);
        mCamera3DView_v_s.setRollMode(Camera3DView.RollMode.RollInTurn);
        mCamera3DView_h_s.setRollMode(Camera3DView.RollMode.RollInTurn);
        mCamera3DView_v_c.setRollMode(Camera3DView.RollMode.Switch);
        mCamera3DView_h_c.setRollMode(Camera3DView.RollMode.Switch);
        mCamera3DView_v_o.setRollMode(Camera3DView.RollMode.Tear);
        mCamera3DView_h_o.setRollMode(Camera3DView.RollMode.Tear);

        mSeekBar.setMax(180);
        mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

                mCamera3DView_v.setRotateDegree(progress);
                mCamera3DView_h.setRotateDegree(progress);
                mCamera3DView_v_3d.setRotateDegree(progress);
                mCamera3DView_h_3d.setRotateDegree(progress);
                mCamera3DView_v_x.setRotateDegree(progress);
                mCamera3DView_h_x.setRotateDegree(progress);
                mCamera3DView_v_t.setRotateDegree(progress);
                mCamera3DView_h_t.setRotateDegree(progress);
                mCamera3DView_v_s.setRotateDegree(progress);
                mCamera3DView_h_s.setRotateDegree(progress);
                mCamera3DView_v_c.setRotateDegree(progress);
                mCamera3DView_h_c.setRotateDegree(progress);
                mCamera3DView_v_o.setRotateDegree(progress);
                mCamera3DView_h_o.setRotateDegree(progress);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });

        mPre.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCamera3DView_v.toPre();
                mCamera3DView_h.toPre();
                mCamera3DView_v_3d.toPre();
                mCamera3DView_h_3d.toPre();
                mCamera3DView_v_x.toPre();
                mCamera3DView_h_x.toPre();
                mCamera3DView_v_t.toPre();
                mCamera3DView_h_t.toPre();
                mCamera3DView_v_s.toPre();
                mCamera3DView_h_s.toPre();
                mCamera3DView_v_c.toPre();
                mCamera3DView_h_c.toPre();
                mCamera3DView_v_o.toPre();
                mCamera3DView_h_o.toPre();
            }
        });

        mNext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCamera3DView_v.toNext();
                mCamera3DView_h.toNext();
                mCamera3DView_v_3d.toNext();
                mCamera3DView_h_3d.toNext();
                mCamera3DView_v_x.toNext();
                mCamera3DView_h_x.toNext();
                mCamera3DView_v_t.toNext();
                mCamera3DView_h_t.toNext();
                mCamera3DView_v_s.toNext();
                mCamera3DView_h_s.toNext();
                mCamera3DView_v_c.toNext();
                mCamera3DView_h_c.toNext();
                mCamera3DView_v_o.toNext();
                mCamera3DView_h_o.toNext();
            }
        });
    }
}
